package holder;

import java.util.List;

import com.example.googlemarketdemo.R;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import conf.constants.URLS;

import utils.BitmapHepler;
import utils.StringUtils;
import utils.UIUtils;
import view.RatioLayout;

import android.view.View;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RatingBar;
import android.widget.TextView;
import base.BaseHolder;
import bean.AppInfoBean;

public class AppDetailPicHolder extends BaseHolder<AppInfoBean> {

	/*-----------  获取控件 ----------*/
	@ViewInject(R.id.app_detail_pic_iv_container)
	LinearLayout mContainerPic;
	
	/*--------- end ----------*/

	@Override
	protected View initHolderView() {
		View view = View.inflate(UIUtils.getContext(), R.layout.item_detail_pic, null);
		//获取控件
		ViewUtils.inject(this, view);
		
		return view;
	}

	@Override
	protected void refreshHolderView(AppInfoBean data) {
		List<String> screenUrls = data.screen;
		for (int i = 0; i < screenUrls.size(); i++) {
			//data
			String url = screenUrls.get(i);
			//如何在不同的分辨率下面也是显示三张图片
			//使用早前在专题使用的RatioLayout控件，创建RatioLayout
			RatioLayout rl = new RatioLayout(UIUtils.getContext());
			rl.setmPicRatio((float)150/250);
			rl.setRelative(RatioLayout.RELATIVE_WIDTH);
			
			
			//图片放置的控件
			ImageView iv = new ImageView(UIUtils.getContext());
			BitmapHepler.display(iv, URLS.IMAGEBASEURL+url);
			rl.addView(iv);
			
			//得到屏幕的宽度
			int screenWidth = UIUtils.getResources().getDisplayMetrics().widthPixels;
			screenWidth = screenWidth - UIUtils.dip2px(20);
			//得到屏幕的1/3
			int width = screenWidth/3;
			int height = LayoutParams.WRAP_CONTENT;
			LayoutParams params = new LayoutParams(width,height);
			
			//设置间距
			if (i!=0) {
				params.leftMargin = UIUtils.dip2px(5);
			}
			
			mContainerPic.addView(rl,params);
		}
		
		
		
	}
	
}
